﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ATEGo
{
    //———————————————————————【调用windows的cmd程序】————————————————————————
    public partial class Executor
    {
        //———————————————————————调用的cmd————————————————————————
        /// <summary>
        /// 执行cmd的程序
        /// </summary>
        private WindowsCmd windowsCmd { get; set; } = new WindowsCmd();

        /// <summary>
        /// 发送两次命令：即会在原来的命令后面再追加一个回车
        /// </summary>
        public void WindowsCmd_SendTwice()
        {
            //默认发送两次命令，以便匹配回显
            windowsCmd.IsExcutedPrompt = true;
        }
        /// <summary>
        /// 发送一次命令：原来命令是什么就发送什么命令
        /// </summary>
        public void WindowsCmd_SendOnce()
        {
            windowsCmd.IsExcutedPrompt = false;
        }

        /// <summary>
        /// 关闭cmd程序，并重新打开
        /// </summary>
        public void WindowsCmd_Open()
        {
            //if (windowsCmd != null)
            //{
            //    windowsCmd.Close();
            //}
            windowsCmd = new WindowsCmd();
            //默认发送两次命令，以便匹配回显
            WindowsCmd_SendTwice();
            //必须是\n
            windowsCmd.NewLine = "\n";
            //得到回显的事件
            windowsCmd.OutputMethod += (msg) =>
            {
                //向外界写log
                WriteCmd(msg);
                //分析回显
                AnalysisEcho(msg);
            };
        }
        /// <summary>
        /// 直接执行cmd
        /// </summary>
        /// <param name="cmd"></param>
        public void WindowsCmd_Execute(string cmd)
        {
            windowsCmd.Excute(cmd);
        }
    }
}
